home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / PAS_0793 / ONLYONCE.PAS < prev    next >
Pascal/Delphi Source File  |  1993-08-01  |  2KB  |  74 lines

  1. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 339 of 373                                                               
  3. From : Wilbert van Leijen                  2:281/256.14         24 Jun 93  20:14 
  4. To   : Ian Chapman                         1:250/322.0                           
  5. Subj : Code For Program                                                       
  6. ────────────────────────────────────────────────────────────────────────────────
  7. 17 Jun 93, Ian Chapman writes to All:
  8.  
  9.  IC> If I have run my program ("IFP.EXE") and then shell to DOS in it, which is
  10.  IC> one of the features, and then run "IFP.EXE" again it will say "Cannot Load
  11.  IC> iNFiNiPLEX More Than Once!".
  12.  
  13.  IC>  My program is called iNFiNiPLEX just to let you know
  14.  
  15. The name of the program doesn't matter.  Technique: set a flag using an
  16. interrupt handler, just like almost any TSR does in order to thwart an attempt 
  17. to install a memory resident program twice.}
  18.  
  19. Program OnlyOnce;
  20. uses Dos;
  21.  
  22. {$M 4096, 0, 0 }
  23.  
  24. Var
  25.   Int16Vector : Pointer;
  26.  
  27. { Using INT 16h: a handler is always present, not as crowdy as INT 2Fh }
  28.  
  29. Procedure Int16Handler; Assembler;
  30.  
  31. ASM
  32.         CMP    AX, 'hi'
  33.         JNE    @1
  34.         MOV    AX, 'HI'
  35.         RETF   2           { preserve flags when using INT 16h }
  36.  
  37. @1:     PUSH   DS
  38.         PUSH   AX
  39.         MOV    AX, SEG @Data
  40.         MOV    DS, AX
  41.         POP    AX
  42.         PUSHF
  43.         CALL   [Int16Vector]
  44.         POP    DS
  45.         RETF   2
  46. end;
  47.  
  48. Function CopyinMemory : Boolean; Assembler;
  49.  
  50. ASM
  51.         MOV   AX, 'hi'
  52.         INT   16h
  53.         CMP   AX, 'HI'
  54.         JE    @1
  55.         MOV   AL, False
  56.         JMP   @2
  57. @1:     MOV   AL, True
  58. @2:
  59. end;
  60.  
  61. Begin
  62.   GetIntVec($16, Int16Vector);
  63.   If CopyInMemory Then
  64.     WriteLn('Refusing to load ONLYONCE twice.')
  65.   Else
  66.     Begin
  67.       SetIntVec($16, @Int16Handler);
  68.       WriteLn('Now shelling to DOS...  Type EXIT to return');
  69.       WriteLn('And do try to run ONLYONCE now!');
  70.       Exec(GetEnv('COMSPEC'), '');
  71.       WriteLn('Back from DOS, terminating ONLYONCE normally.');
  72.       SetIntVec($16, Int16Vector);
  73.     end;
  74. end.